package cn.tedu;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo09 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = scan.nextLine();
        System.out.println("请输入密码:");
        String password = scan.nextLine();
        System.out.println("请输入昵称:");
        String nick = scan.nextLine();
        try (Connection connection = DBUtils.getConn()){
            Statement statement = connection.createStatement();
            statement.executeUpdate("insert into user values (null,'"+username+"','"+password+"','"+nick+"')");
            ResultSet rs =statement.executeQuery("select * from user ");
            while (rs.next()){
                String name = rs.getString(2);
                String pw = rs.getString(3);
                String nk = rs.getString(4);
                System.out.println(name+",  "+pw+",  "+nk);

            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
